<template>
    <div style="height: 100%; width: 100%; position: relative" ref="maindev">
        <div class="pagetop" :style="pagetopstyle">
            <div style="width: 100%">
                <el-col>
                    <div ref="buttondiv">
                        <!-- <vxe-toolbar>
                            <template v-slot:buttons> -->
                        <table style="width: 100%; font-size: 12px" border="0">
                            <!-- <col style="width: 4%" />
                            <col style="width: 9%" />
                            <col style="width: 1%" />
                            <col style="width: 9%" />
                            <col style="width: 4%" />
                            <col style="width: 10%" />
                            <col style="width: 4%" />
                            <col style="width: 10%" />
                            <col style="width: 4%" />
                            <col style="width: 10%" />
                            <col style="width: 35%" /> -->
                            <tr>
                                <td style="width:50px">
                                    <el-dropdown @command="handleCommand" style="font-size: 12px">
                                    <u class="el-dropdown-link">
                                        {{ datename }}
                                    </u>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item command="标本日期">
                                            <font font-size="12px">标本日期</font>
                                        </el-dropdown-item>
                                        <el-dropdown-item command="接收时间">
                                            <font font-size="12px">接收时间</font>
                                        </el-dropdown-item>
                                        <el-dropdown-item command="采样时间">
                                            <font font-size="12px">采样时间</font>
                                        </el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>

                                </td>
                                <!-- <td>
                                    <el-date-picker v-model="sel_date" type="daterange" start-placeholder="开始日期" range-separator="至" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width:240px;">
                                    </el-date-picker>
                                </td> -->
                                <td style="width:148px">
                                    <el-date-picker v-model="sample_startdt" :able="false" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width: 148px; min-width: 148px" :clearable="false"> </el-date-picker>
                                </td>
                                <td style="width:20px" align="center">至</td>
                                <td style="width:148px">
                                    <el-date-picker v-model="sample_enddt" type="datetime" :able="false" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" style="width: 148px; min-width: 148px" :clearable="false"> </el-date-picker>
                                </td>
                                <td style="width:50px">报告单元</td>
                                <td style="width:160px">
                                    <rm-ddl-rptunit prgno="LIS241" :multiple_choice="true" clearable v-model="sel_rptunitlist" width="160px" @change="rptunitchange"></rm-ddl-rptunit>
                                </td>
                                <td style="width:50px">病人类型</td>
                                <td style="width:150px">
                                    <el-select v-model="sel_pattypecode" clearable style="width: 150px">
                                        <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                                    </el-select>
                                </td>
                                <td rowspan="3" style="width:120px">
                                    <div style="border: 1px solid #000; height: 88px; margin-top: 0px">
                                        <el-radio-group v-model="sel_type" size="mini">
                                            <table style="height: 88px">
                                                <tr>
                                                    <td style="text-align: left; line-height: 33%">
                                                        <el-radio label="1" width="100%">未审核报告+未完成标本</el-radio>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="text-align: left; line-height: 33%">
                                                        <el-radio label="2" width="100%">未审核报告</el-radio>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="text-align: left; line-height: 33%">
                                                        <el-radio label="3" width="100%">未完成标本</el-radio>
                                                    </td>
                                                </tr>
                                            </table>
                                        </el-radio-group>
                                    </div>
                                </td>
                                <td style="text-align: left" colspan="2">
                                    <el-checkbox v-model="onlyrptunit" false-label="0" true-label="1" style="width: 110px" @change="haveChange(3)">包含本单元未上机但存在本单元对照申请项目的条码</el-checkbox>
                                </td>
                                <td></td>
                            </tr>
                            <tr>
                                <td>报告项目</td>
                                <td colspan="3">
                                    <el-input ref="txtitemname" v-model="rpt_itemname" placeholder="双击选择报告项目" @dblclick.native="OpenRptitem" clearable @clear="clearitem"></el-input>
                                    <!-- <rm-ddl-rptitem prgno="LIS241" :germmode="false" :filterable="true" v-model="sel_rptitemcode" width="100%" :appendtobody="true"></rm-ddl-rptitem> -->
                                </td>
                                <td>检验组别</td>
                                <td >
                                    <el-select v-model="labgroupid" placeholder="选择检验组" clearable style="width: 100%">
                                        <el-option v-for="(item, index) in gList" :key="index" :label="item.labgroupname" :value="item.labgroupid"></el-option>
                                    </el-select>
                                </td>
                                <td>分单类别</td>
                                <td>
                                    <rm-ddl-common dataname="分单类别" datatype="reqgroup" appendtobody width="150px"  v-model="reqgroupid" @change="reqgroupChange"></rm-ddl-common>
                                </td>
                                <td style="text-align: left;width: 66px;">
                                    <el-checkbox v-model="hasBac" false-label="0" true-label="1" style="width: 60px" @change="haveChange(1)">不包含细菌</el-checkbox>
                                </td>
                                <td style="text-align: left;width: 70px;">
                                    <el-checkbox v-model="hasMerge" false-label="0" true-label="1" style="width: 70px" @change="haveChange(2)">含已合并报告</el-checkbox>
                                </td>
                            </tr>
                            <tr>
                                <td>申请项目</td>
                                <td colspan="3">
                                    <!-- <rm-ddl-common datatype="reqitem" dataname="申请项目" :filterable="true" v-model="sel_req_itemcode" size="mini" width="100%" :clearable="true" :appendtobody="true" key="dialogreq_itemcode"></rm-ddl-common> -->
                                    <el-input v-model="req_itemname" placeholder="双击选择申请项目" @dblclick.native="OpenReqitem" clearable @clear="clearreqitem"></el-input>
                                </td>
                                <td>执行科室</td>
                                <td >
                                    <rm-ddl-common datatype="dept" dataname="科室" v-model="sel_dept" width="100%" @change="deptChange"></rm-ddl-common>
                                </td>
                                <td>条码号</td>
                                <td><el-input v-model="txtbarcode" style="width: 150px" ref="reftxtbarcode" clearable></el-input></td>
                                <td style="text-align: left">
                                    <el-checkbox v-model="isemer" false-label="0" true-label="1" style="width: 80px" @change="haveChange(4)">仅显示急诊标本</el-checkbox>
                                </td>
                                <td></td>
                            </tr>
                            <tr v-show="show_sel">
                                <td>送检医院</td>
                                <td colspan="3">
                                    <rm-ddl-common datatype="hospital" dataname="医院" v-model="sel_hospital" width="100%" @change="hospChange"></rm-ddl-common>
                                </td>
                                <td @click="showhelp('grouplabdept')">检验科室<span style="color:blue" class="el-icon-info"></span></td>
                                <td>
                                    <rm-ddl-common datatype="labdept" dataname="检验科室" v-model="labdept" width="100%" @change="labdeptChange"></rm-ddl-common>
                                </td>
                                <!-- <td>送往报告单元</td>
                                <td>
                                    <rm-ddl-rptunit prgno="LIS241" :multiple_choice="true" v-model="to_rptunitlist" width="100%" @change="torptunitChange"></rm-ddl-rptunit>
                                </td> -->
                                <td>分单类别组合</td>
                                <td colspan="2">
                                    <rm-ddl-common datatype="groupcombid" dataname="分单类别组合" v-model="groupcombid" width="100%" @change="groupcombChange"></rm-ddl-common>
                                </td>
                                <td></td>
                            </tr>
                            <!-- <tr v-show="show_sel">
                                <td @click="showhelp('grouplabdept')">检验科室<span style="color:blue" class="el-icon-info"></span></td>
                                <td colspan="3">
                                    <rm-ddl-common datatype="labdept" dataname="检验科室" v-model="labdept" width="100%" @change="labdeptChange"></rm-ddl-common>
                                </td>
                            </tr> -->
                            <tr>
                                <td colspan="16" align="right">
                                    <el-link :underline="false" @click="btn_openselEvent">{{ show_sel ? "收起▲" : "展开▼" }}</el-link>
                                    <el-button icon="el-icon-search" v-has="'PINQUERY'" type="primary" style="align: left" @click="btnQuery">查询</el-button>
                                    <el-button icon="el-icon-sort" @click="btnSort">排序</el-button>
                                    <el-button icon="el-icon-delete" @click="btnClear">清除</el-button>
                                    <!-- <el-button icon="el-icon-printer" @click="btnPrint(1)">查看申请结果</el-button> -->
                                    <el-button icon="el-icon-upload2" @click="btnExportRpt()">导出报告</el-button>
                                    <el-button icon="el-icon-printer" @click="btnPrint(1)">打印</el-button>
                                    <el-button @click.native="btnPrint(2)" class="el-icon-edit-outline">打印样式设计</el-button>
                                </td>
                            </tr>
                        </table>
                        <!-- </template>
                        </vxe-toolbar> -->
                    </div>
                </el-col>
            </div>
        </div>
        <div :style="pagecenter">
            <rm-layout-right :fixsize="520" :splitwidth="5" :minfixsize="200" :maxflxsize="2000">
                <div :style="middle_center">
                    <vxe-table :data.sync="report_date" :loading="report_Loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border :height="reportheight" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="reporttable" resizable show-overflow size="mini" :row-class-name="reportRowName" show-header-overflow :optimization="{ animat: false }" @current-change="reportchange_Event" :cell-class-name="reportCellName" @cell-click="cellClickEvent" @cell-dblclick="cellDblClickEvent" header-align="center">
                        <vxe-table-column field="labgroupname" title="检验组" width="60" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="pat_typecodename" title="病人来源" width="60" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="req_groupna" title="分单类别" width="80" show-overflow align="center" sortable></vxe-table-column>
                        <vxe-table-column field="rptunitname" title="报告单元" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column align="center" field="sampledate" title="标本日期" width="80" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="sampleno" align="center" title="标本编号" width="80" show-overflow :sort-width="20" sortable>
                            <template v-slot="{ row }">
                                <span style="color:blue;">{{row.sampleno}}</span>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="input_dt" align="center" title="登记时间" width="140" show-overflow sortable></vxe-table-column> 
                        <vxe-table-column field="emer_flag" title="加急" width="40" align="center" sortable></vxe-table-column>
                        <vxe-table-column field="sample_items" align="center" title="申请项目（简称，部分）" width="200" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="barcode" align="center" title="条码号" width="120" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_deptname" align="center" title="申请科室" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="perform_deptname" align="center" title="执行科室" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="recieve_dt" align="center" title="接收时间" width="140" show-overflow sortable ></vxe-table-column>
                        <vxe-table-column field="recieve_username" align="center" title="接收人" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_name" title="姓名" width="60" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_no" align="center" title="病历号" width="40" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="req_stat" title="状态" width="90" show-overflow :formatter="FormatData" sortable></vxe-table-column>
                        <vxe-table-column field="req_docno" align="center" title="申请医生" width="50" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_bedno" align="center" title="床号" width="80" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="specimen_codename" title="标本类型" width="100" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_sex" title="性别" width="40" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="pat_agestr" title="年龄" width="100" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="create_username" align="center" title="创建人" width="90" show-overflow></vxe-table-column>
                        <vxe-table-column field="print_dt" title="打印/执行时间" width="250" show-overflow></vxe-table-column>
                        <vxe-table-column field="print_username" align="center" title="打印/执行人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="sampled_dt" align="center" title="采样时间" width="140" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="sampled_username" title="采样人" width="110" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_dt" title="申请时间" width="100" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="prereport_dt" align="center" title="预出报告时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="send_dt" align="center" title="送出时间" width="140" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="send_username" align="center" title="送出人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_dt" title="计价时间" width="120" show-overflow sortable></vxe-table-column>
                        <vxe-table-column field="charge_username" align="center" title="计价人" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="amount" align="center" title="实收金额" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_flag" align="center" title="计价标志" width="70" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_comm" title="医生备注" width="130" show-overflow></vxe-table-column>
                        <vxe-table-column field="pat_birth" title="生日" width="150" show-overflow></vxe-table-column>
                        <vxe-table-column field="charge_typeno" title="费别代码" width="100" show-overflow></vxe-table-column>
                        <vxe-table-column field="req_wardno" align="center" title="病区" width="50" show-overflow></vxe-table-column>
                        <vxe-table-column field="original_reqno" title="原始申请单号" width="150" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_dt" align="center" title="剔回时间" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_username" align="center" title="剔回人" width="70" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_reason" align="center" title="剔回原因" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reject_count" align="center" title="剔回次数" width="90" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
                        <vxe-table-column field="reqtype" align="center" title="申请单类别" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="reportid" title="报告ID" width="160" show-overflow></vxe-table-column>
                        <vxe-table-column field="cp_itemnames" title="申请项目（未上机）" width="180" show-overflow></vxe-table-column>
                        <vxe-table-column field="report_username" align="center" title="检验者" width="140" show-overflow></vxe-table-column>
                        <vxe-table-column field="report_comm" title="报告备注" width="100" show-overflow></vxe-table-column>
                        <template v-slot:fix>
                            <div style="font-size: 12px; padding-top: 3px; background-color: #fff">
                                <span style="color: red; margin-left: 10px; float: right">合计: {{ rpt_amount }}</span>
                                <div style="clear: both"></div>
                            </div>
                        </template>
                    </vxe-table>
                </div>
                <template v-slot:fix>
                    <div class="middle-right">
                        <div class="right-inser">
                            <div class="middle-tab-top">
                                <vxe-table :data.sync="result_data" :loading="result_Loading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row header-align="center" highlight-hover-column highlight-hover-row how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }">
                                    <vxe-table-column field="rpt_itemname" sortable title="检验项目" width="220" show-overflow>
                                        <template v-slot="{ row }">
                                            <div v-if="row.alertflag == '1'" style="background: red; padding: 0px 10px">
                                                {{ row.rpt_itemname }}
                                            </div>
                                            <div v-else style="padding: 0px 10px">
                                                {{ row.rpt_itemname }}
                                            </div>
                                        </template></vxe-table-column
                                    >
                                    <vxe-table-column field="result_str" sortable title="检测结果" width="80" show-overflow>
                                        <template v-slot="{ row }">
                                            <div :style="{ background: row.cp_resultbackgroundcolor, color: row.cp_resultcolor }" style="padding: 0px 10px">
                                                {{ row.result_str }}
                                            </div>
                                        </template></vxe-table-column
                                    >
                                    <vxe-table-column field="result_unit" sortable title="单位" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_ref" sortable title="参考值" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="alertflag" align="center" sortable title="危急标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_flag" align="center" sortable title="结果标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="groupseq" align="center" sortable title="分组序号" width="80" show-overflow></vxe-table-column>
                                    <vxe-table-column field="seq" sortable title="打印序号" width="150" show-overflow></vxe-table-column>
                                    <vxe-table-column field="reportid" align="center" sortable title="项目ID" width="60" show-overflow></vxe-table-column>vxe-table-column>
                                    <template v-slot:fix>
                                        <div style="font-size: 12px; padding-top: 3px; background-color: #fff">
                                            <span style="color: red; margin-left: 10px; float: right">合计: {{ result_amount }}</span>
                                            <div style="clear: both"></div>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                            <div class="middle-tab-bottom">
                                <vxe-table :data.sync="resusltmed_date" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border :height="ymresultheight" :row-class-name="ResultRowName" how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center">
                                    <vxe-table-column field="itemcode_en" sortable title="应做项目" width="220" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_str" sortable title="检验结果" width="100" show-overflow>
                                        <template v-slot="{ row }">
                                            <div :style="{ background: row.cp_resultbackgroundcolor, color: row.cp_resultcolor }" style="padding: 0px 10px">
                                                {{ row.result_str }}
                                            </div>
                                        </template>
                                    </vxe-table-column>
                                    <vxe-table-column field="rptunitid" sortable title="报告单元" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="sampledate" sortable title="标本日期" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="sampleno" sortable title="标本号" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rpt_itemname" sortable title="项目名称" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_ref" sortable title="参考值" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_unit" sortable title="单位" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="alertflag" sortable title="危急标志" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_flag" sortable title="结果标志" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="stat_flag" sortable title="状态" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="seq" sortable title="序号" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="reportid" sortable title="项目ID" width="100" show-overflow></vxe-table-column>
                                    <template v-slot:fix>
                                        <div style="font-size: 12px; padding-top: 3px; background-color: #fff">
                                            <span style="color: red; margin-left: 10px; float: right">合计: {{ resusltmed_amount }}</span>
                                            <div style="clear: both"></div>
                                        </div>
                                    </template>
                                </vxe-table>
                            </div>
                        </div>
                    </div>
                </template>
            </rm-layout-right>
        </div>

        <!--多选弹窗--->
        <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="outerVisible" :destroy-on-close="true" title="报告项目">
            <rm-chkboxSelect2
                prgno="LIS310"
                @cancel="
                    outerVisible = false;
                    diagx = false;
                "
                :isAllRpt="1"
                :rptunitid="rptunit"
                :rptunitdisabled="true"
                @selitem="addrptitem"
                @selitems="addrptitems"
                ref="rptdialog"
            ></rm-chkboxSelect2>
        </el-dialog>

        <el-dialog width="1000px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="reqouterVisible" :destroy-on-close="true" title="申请项目">
            <rm-pop-common datatype="reqitem" dataname="申请项目" :filterable="true" v-model="sel_req_itemcode" size="mini" width="100%" :clearable="true" :multiple="true" :appendtobody="true" key="dialogreq_itemcode" @change="reqitemchange" @cancel="reqouterVisible = false"></rm-pop-common>
        </el-dialog>
    </div>
</template>

<script>
import { Promise } from "q";
import { invalid } from "moment";
import XE from "xe-utils"; //引入工具类
import checkbox from "../../../../element-ui/packages/checkbox/src/checkbox.vue";
export default {
    components: { checkbox },
    name: "LIS241",
    data() {
        return {
            pagetopstyle: {
                height: "135px",
            },
            pagecenter: {
                position: "absolute",
                top: "138px",
                bottom: "0px",
                overflow: "auto",
                width: "100%",
                left: "0px",
            },
            middle_center: {
                position: "absolute",
                height: "100%",
                right: "0px",
                left: "0px",
                overflow: "auto",
            },
            show_sel: false,
            report_Loading: false,
            outerVisible: false,
            reqouterVisible: false,
            isemer: "0",
            hasBac: "1",
            hasMerge:"1",
            onlyrptunit: "0",
            pattypeOption: [],
            tableColumn: [],
            sortArr: [],
            report_date: [],
            sel_rptunit: "",
            sel_rptunitlist: "80",
            sel_dept: "",
            sel_hospital: "",
            sel_type: "1",
            sel_patno: "",
            sel_reqbedno: "",
            txtbarcode: "",
            to_rptunitlist: "",
            sel_req_itemcode: "",
            labgroupid: "",
            reqgroupid: "",
            sample_startdt: "",
            sample_enddt: XE.toDateString(new Date(), "yyyy-MM-dd 23:59:59"),
            rptunit: "",
            rpt_itemname: "",
            req_itemname: "",
            sel_patname: "",
            sel_patname_mh: false,
            sel_pattypecode: "0",
            sel_specimencode: "",
            sel_sampleno: "",
            sel_emerflag: "all",
            sel_reqdeptno: "",
            sel_rflag: "all",
            sel_rptitemcode: "",
            sel_barcode: "",
            sel_reqdocno: "",
            sel_patdiag: "",
            sel_reqwardno: "",
            sel_od_cutoff: "0",
            gList: [],
            statusOptions: [],
            is_ym: true, //是否显示药敏
            result_data: [],
            result_Loading: false,
            resusltmed_date: [],
            master_data: [],
            master_Loading: false,
            cellreportid: "",
            reportheight: "auto",
            resultheight: "auto",
            result1text: "",
            result2text: "",
            result3text: "",
            result1: "",
            result2: "",
            result3: "",
            ymresultheight: "auto",
            buttonWidth: "",
            rpt_amount: 0,
            result_amount: 0,
            resusltmed_amount: 0,
            ymresultitem_amount: 0,
            styleid: "5034",
            operate: "",
            macaddress: "",
            PushToFlag: true, // 双击标本号跳转对应报告单元确认消息是否已经弹出过标志
            rptunitAll: [],
            datetype:"1",
            datename: "标本日期",
            exportTableColLen: 0,
            reqgroupname: "",
            deptname: "",
            hospname: "",
            torptunitsname: "",
            rptunitsname: "",
            labdept: "",
            labdeptname: "",
            groupcombid: "",
            groupcombname: "",
        };
    },
    created() {
        this.sel_pattypecode = "";
        this.sel_rptunitlist = "";
        this.hasBac = localStorage.getItem("lis241hasBac");
        this.hasMerge = localStorage.getItem("lis241hasMerge");
        this.onlyrptunit = localStorage.getItem("lis241onlyrptunit");
        this.isemer = localStorage.getItem("lis241isemer");
        //this.btnQuery();
        this.initOption();
        //this.btnClear();
    },
    updated() {
        this.getButtonWidth();
    },
    mounted() {
        this.sample_startdt=XE.toDateString(XE.getWhatDay(new Date(), -1), "yyyy-MM-dd 00:00:00");
    },
    methods: {
        handleCommand(name) {
            this.datename = name;
            if (name == "标本日期") this.datetype = "1";
            else if (name == "接收时间") this.datetype = "2";
            else if (name == "采样时间") this.datetype = "3";
        },
        async initOption() {
            if (typeof jsObj != "undefined") {
                var computeInfo = jsObj.GetComputeInfo();
                var arr = computeInfo.split("\r");
                if (arr.length == 3) {
                    this.macaddress = arr[0];
                }
            } else {
                this.macaddress = "Default";
            }
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS241",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                });
                this.rptunitAll = res.rptunitAll;
                this.statusOptions = res.dt1;
                this.gList = res.glist;
                this.pattypeOption = res.pattypeOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        InitColumn() {
            if (this.tableColumn.length == 0) {
                let columns = this.$refs.reporttable.getColumns();
                columns.forEach((item) => {
                    this.tableColumn.push({ title: item.title, field: item.property });
                });
            }
        },
        btnQuery() {
            this.report_Loading = true;
            this.sqlWhere = "";
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS241",
                    method: "post",
                    timeout: 600000,
                    data: {
                        action: "lab_report_query",
                        datetype:this.datetype,
                        sample_startdt: this.sample_startdt,
                        sample_enddt: this.sample_enddt,
                        sel_rptunitlist: this.sel_rptunitlist,
                        sel_pattypecode: this.sel_pattypecode,
                        sel_dept: this.sel_dept,
                        sel_rptitemcode: this.sel_rptitemcode,
                        sel_type: this.sel_type,
                        labgroupid: this.labgroupid,
                        reqgroupid: this.reqgroupid,
                        sel_req_itemcode: this.sel_req_itemcode,
                        hasBac: this.hasBac,
                        hasMerge: this.hasMerge,
                        sel_hospital: this.sel_hospital,
                        txtbarcode: this.txtbarcode,
                        to_rptunitlist: this.to_rptunitlist,
                        onlyrptunit: this.onlyrptunit,
                        isemer: this.isemer,
                        sortArr: this.sortArr,
                        groupcombid: this.groupcombid,
                        labdept: this.labdept,
                    },
                })
                .then((res) => {
                    this.report_date = res.data;
                    this.result_data = [];
                    this.report_Loading = false;
                    this.InitColumn();
                    // if (res.total > 5000) {
                    //     this.$message({
                    //         type: "info",
                    //         message: "超过5000行只显示前5000行数据！",
                    //     });
                    // }
                    if (this.report_date.length > 0) {
                        this.fuc_get_labresult(this.report_date[0]);
                        this.cellreportid = this.report_date[0].reportid;
                    }
                    this.rpt_amount = res.total;
                    this.show_sel = true;
                    this.btn_openselEvent();
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        btnSort() {
            this.$rmsort(
                { tableColumn: this.tableColumn, sortArr: this.sortArr },
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            )
                .then((res) => {
                    this.sortArr = res.data;
                    this.btnQuery();
                })
                .catch(() => {});
        },
        OpenRptitem() {
            this.outerVisible = true;
        },
        clearitem() {
            this.sel_rptitemcode = "";
            this.rpt_itemname = "";
        },
        rptunitchange(c, n) {
            this.sel_rptunitlist = c;
            this.rptunitsname = n;
        },
        addrptitem(c, n) {
            this.outerVisible = false;
            this.sel_rptitemcode = c;
            this.rpt_itemname = n;
        },
        addrptitems(rows) {
            this.rpt_itemcode = "";
            this.rpt_itemname = "";
            if (rows.length > 0) {
                rows.forEach((x) => {
                    this.sel_rptitemcode = this.sel_rptitemcode + x.rpt_itemcode + ",";
                    this.rpt_itemname = this.rpt_itemname + x.rpt_itemname + ",";
                });
            }
            this.rpt_itemname = this.rpt_itemname.substr(0, this.rpt_itemname.length - 1);
            this.outerVisible = false;
        },
        OpenReqitem() {
            this.reqouterVisible = true;
        },
        reqitemchange(c, v) {
            if (c.length > 0) {
                c.forEach((x) => {
                    this.sel_req_itemcode = this.sel_req_itemcode + x.hidkey + ",";
                    this.req_itemname = this.req_itemname + x.hidname + ",";
                });
            }
            this.req_itemname = this.req_itemname.substr(0, this.req_itemname.length - 1);
            this.reqouterVisible = false;
        },
        clearreqitem() {
            this.sel_req_itemcode = "";
            this.req_itemname = "";
        },
        reportchange_Event({ row, rowIndex, column, columnIndex }, event) {
            this.fuc_get_labresult(row);
        },
        fuc_get_labresult(row) {
            this.result_Loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS241",
                    method: "post",
                    data: {
                        action: "get_labresult",
                        reportid: row.reportid,
                        barcode: row.barcode,
                        rptunitid: row.rptunitid,
                        macaddress: this.macaddress,
                    },
                })
                .then((res) => {
                    this.result_data = res.data1;
                    this.resusltmed_date = res.data2;
                    this.result_amount = this.result_data.length;
                    this.resusltmed_amount = this.resusltmed_date.length;
                    this.result_Loading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        btn_openselEvent() {
            let mainheight = this.$refs.maindev.offsetHeight;
            this.show_sel = !this.show_sel;
            // this.$nextTick(() => {
            if (this.show_sel) {
                this.pagetopstyle.height = "170px";
                this.pagecenter.top = "173px";
                // this.pagetopstyle.height = "195px";
                // this.pagecenter.top = "200px";
                this.reportheight = mainheight - 170;
                if (this.is_ym) {
                    this.ymresultheight = mainheight - 373;
                } else {
                    this.resultheight = mainheight - 175;
                }
            } else {
                this.pagetopstyle.height = "135px";
                this.pagecenter.top = "138px";
                this.reportheight = mainheight - 140;
                if (this.is_ym) {
                    this.ymresultheight = mainheight - 343;
                } else {
                    this.resultheight = mainheight - 110;
                }
            }
            // } else {
            //     this.pagetopstyle.height = "36px";
            //     this.pagecenter.top = "40px";
            //     this.reportheight = mainheight - 45;
            //     if (this.is_ym) {
            //         this.ymresultheight = mainheight - 247;
            //     } else {
            //         this.resultheight = mainheight - 45;
            //     }
            // }
            // });
        },
        btnClear() {
            this.show_sel = false;
            this.report_Loading = false;
            this.report_date = [];
            this.result_data = [];
            this.resusltmed_date = [];

            // this.sel_date = [XE.toDateString(XE.getWhatDay(new Date(), -30), "yyyy-MM-dd"), XE.toDateString(new Date(), "yyyy-MM-dd")];
            this.sample_startdt = XE.toDateString(XE.getWhatDay(new Date(), -30), XE.toDateString(new Date(), "yyyy-MM-dd 00:00:00"));
            this.sample_enddt = XE.toDateString(new Date(), "yyyy-MM-dd 23:59:59");
            this.sel_rptunitlist = "";
            this.sel_pattypecode = "";
            this.sel_dept = "";
            this.sel_rptitemcode = "";
            this.sel_type = "1";
            this.labgroupid = "";
            this.reqgroupid = "";
            this.sel_req_itemcode = "";
            this.sel_hospital = "";
            this.txtbarcode = "";
            this.to_rptunitlist = "";
            this.rpt_itemname = "";
            this.req_itemname = "";
            this.sortArr = [];
            this.groupcombid = "";
        },
        btnPrint(index) {
            var data = this.$refs.reporttable.afterFullData;
            if (data.length > 0) {
                const rload = this.$pub.openLoading(this, "正在打开报表设计器，请稍候……");
                let column = this.$refs.reporttable.getTableColumn().tableColumn;
                let str = JSON.stringify(this.$pub.InitColumn(column));
                str += "\r";
                data.forEach((e) => {
                    e.total = this.total;
                });
                str += JSON.stringify(data);
                let sql = btoa(encodeURIComponent(str));
                if (index == "1") {
                    jsObj.PrintCustomJsonReport("5063", sql, this.userno, "标本上机未报告清单样式", "");
                } else {
                    jsObj.SetCustomJsonPrintConfig("5063", sql, this.userno, "标本上机未报告清单样式");
                }
                rload.close();
            } else {
                this.$alert("请选中要打印的数据！");
            }
        },
        cellClickEvent({ row, column }) {
            this.cellreportid = row.reportid;
        },
        cellDblClickEvent({ row, column }) {
            if (column.property == "sampleno") {
                if (this.PushToFlag) {
                    this.$confirm("是否直接跳转到报告处理中查看？", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    })
                        .then(() => {
                            this.PushToUnit(row);
                            this.PushToFlag = false;
                        })
                        .catch(() => { });
                } else this.PushToUnit(row);
            }
        },
        PushToUnit(row) {
            var pageinfo = this.$tool.getSession("RptPageInfo");
            var pagearr = JSON.parse(pageinfo);
            var multi = this.$tool.getLocalConfig("lis310multiple");
            row.AddBy410 = "1";
            row.sampledate = XE.toDateString(row.sampledate, "yyyy-MM-dd"),
            this.$tool.setSession("RptTo", JSON.stringify(row));
            if (pagearr == null) pagearr = [];
            var prgno = "/LIS310";
            var unitinfo = this.rptunitAll[row.rptunitid];
            if (unitinfo) {
                switch (unitinfo.reporttype) {
                    case "10":
                        prgno = "/LIS310";
                        break;
                    case "20":
                        prgno = "/LIS311";
                        break;
                    case "50":
                        prgno = "/LIS312";
                        break;
                    case "40":
                        prgno = "/LIS313";
                        break;
                    case "60":
                        prgno = "/LIS314";
                        break;
                }
            }
            if (multi == "1") {
                //多开
                if (pagearr && pagearr.length == 0) {
                    pagearr.push({ id: 1, rptunitid: row.rptunitid, path: prgno + "?id=1", multi: "" });
                    this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                    this.$router.push({ path: prgno + "?id=1" });
                } else {
                    var findone = pagearr.find((item) => item.rptunitid == row.rptunitid);
                    //如果找到了该报告单元已打开，直接把他移动到最后,这样激活报告处理时直接取最后一个就行
                    if (findone) {
                        var idx = pagearr.indexOf(findone);
                        if (idx !== -1) {
                            var item = pagearr.splice(idx, 1)[0];
                            item.exci = '1';
                            pagearr.push(item);  
                        }
                        this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                        this.$router.push({ path: findone.path });
                    }
                    else {
                        var id = pagearr[pagearr.length - 1].id - 0 + 1;
                        pagearr.push({ id: id, rptunitid: row.rptunitid, path: prgno + "?id=" + id, multi: "" });
                        this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                        this.$router.push({ path: prgno + "?id=" + id });
                    }
                }
            } else {
                //单开
                if (pagearr && pagearr.length == 0) {
                    pagearr.push({ id: 0, rptunitid: row.rptunitid, path: prgno, multi: "" });
                    this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                    this.$router.push({ path: prgno });
                }
                else{
                    //已经打开页面
                    pagearr=[];
                    pagearr.push({ id: 0, rptunitid: row.rptunitid, path: prgno, multi: "" ,exci:'1'});
                    this.$tool.setSession("RptPageInfo", JSON.stringify(pagearr));
                    this.$router.push({ path: prgno});
                }
            }
        },
        //"rm-cancel"; //作废
        //"rm-disable"; //禁用
        //"rm-readonly"; //只读
        //"rm-alert"; //警告
        reportRowName({ row, rowIndex }) {
            if (row.rechk_dt != "" && row.rechk_dt != " " && row.rechk_dt != null) {
                if (XE.toNumber(row.print_count) > 0) {
                    return "rm-gray"; //审核过打印的
                } else {
                    return "colrow"; //没打印的
                }
            }
        },
        reportCellName({ row, rowIndex, column, columnIndex }) {
            if (column.property == "alter_flag") {
                if (row.alter_flag == "1" || row.alter_flag == "2") {
                    return "colred";
                }
            }
            // if (column.property == "emer_flag") {
            //     if (row.emer_flag != "0") {
            //         return "rm_cell_green";
            //     }
            // }
            if (column.property == "redo_flag") {
                if (row.redo_flag == "2" || row.redo_flag == "3") {
                    return "colgreen";
                }
            }
            if (column.property == "req_stat") {
                return this.$pub.getreqstatclass(row.req_stat);
            }
        },
        FormatData({ cellValue, row, column }) {
            if (column.property == "req_stat") {
                try {
                    if (row.req_stat != "") {
                        return this.statusOptions.find((m) => m.value == row.req_stat).label;
                    } else {
                        return cellValue;
                    }
                } catch (e) {
                    return cellValue;
                }
            } else {
                return cellValue;
            }
        },
        getButtonWidth() {
            this.buttonWidth = this.$refs.buttondiv.offsetWidth + "px";
        },
        reqgroupChange(code, name) {
            this.reqgroupid = code;
            this.reqgroupname = name;
        },
        deptChange(code, name) {
            this.sel_dept = code;
            this.deptname = name;
        },
        hospChange(code, name) {
            this.sel_hospital = code;
            this.hospname = name;
        },
        torptunitChange(code, name) {
            this.to_rptunitlist = code;
            this.torptunitsname = name;
        },
        groupcombChange(code, name) {
            this.groupcombid = code;
            this.groupcombname = name;
        },
        labdeptChange(code, name){
            this.labdept = code;
            this.labdeptname = name;
        },
        btnExportRpt() {
            let data = this.getExportData();
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS241 标本上机未报告清单 result.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = this.datename + ":" + XE.toDateString(this.sample_startdt, "yyyy-MM-dd HH:mm:ss") + "至" + XE.toDateString(this.sample_enddt, "yyyy-MM-dd HH:mm:ss") + "; ";
            if(this.sel_pattypecode) filtertxt += "病人来源:" + this.getOptionName(this.pattypeOption.filter((item) =>  this.sel_pattypecode == item.data)) + "; ";
            if(this.sel_rptunitlist) filtertxt += "报告单元:" + this.rptunitsname + "; ";
            if(this.sel_type) filtertxt += "标本状态:" + (this.sel_type == "2" ? "未审核报告" : this.sel_type == "3" ? "未完成标本" : "未审核报告+未完成标本") + "; ";
            if(this.hasBac == "1") filtertxt += "不包含细菌; ";
            if(this.labgroupid) filtertxt += "检验组:" + this.getOptionName(this.gList.filter((item) =>  this.labgroupid == item.labgroupid)) + "; ";
            if(this.reqgroupid) filtertxt += "分单类别:" + this.reqgroupname + "; ";
            if(this.rpt_itemname) filtertxt += "报告项目:" + this.rpt_itemname + "; ";
            if(this.hasMerge == "1") filtertxt += "含已合并报告; ";
            if(this.sel_dept) filtertxt += "执行科室:" + this.deptname + "; ";
            if(this.req_itemname) filtertxt += "申请项目:" + this.req_itemname + "; ";
            if(this.txtbarcode) filtertxt += "条码号:" + this.txtbarcode + "; ";
            if(this.onlyrptunit == "1") filtertxt += "仅显示当前报告单元; ";
            if(this.sel_hospital) filtertxt += "送检医院:" + this.hospname + "; ";
            //if(this.to_rptunitlist) filtertxt += "送往报告单元:" + this.torptunitsname + "; ";
            if(this.isemer == "1") filtertxt += "仅显示急诊标本; ";
            if(this.groupcombid) filtertxt += "分单类别组合:" + this.groupcombname + "; ";
            if(this.labdept) filtertxt += "检验科室:" + this.labdeptname + "; ";
            return filtertxt;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("labgroupname")) {
                        optionname += item.labgroupname + ",";
                    } else if(item.hasOwnProperty("display")) {
                        optionname += item.display + ",";
                    } else {
                        optionname += item.label + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        getExportData() {
            let datas = [];
            datas = this.$refs.reporttable.afterFullData;
            var allcolumns = this.$refs.reporttable.getColumns();

            var tableColumn = [];
            for (let i = 0; i < allcolumns.length; i++) {
                tableColumn.push({
                    field: allcolumns[i].property,
                    title: allcolumns[i].title,
                });
            }
            this.exportTableColLen = tableColumn.length;
            let columns = tableColumn.filter((item) => item.field);
            let headers = [columns.map((item) => item.title)];
            return headers.concat(
                datas.map((row) => {
                    return columns.map((column) => {
                        return row[column.field];
                    });
                })
            );
        },
        ResultRowName({ row, rowIndex }) {
            if (!row.result_str || row.result_str == "pending" || row.result_str == "未做" || row.result_str == "已上机") {
                return "rm_cell_yellow";
            }
        },
         haveChange(type) {
            switch (type) {
                case 1:
                    localStorage.setItem("lis241hasBac", this.hasBac);
                    break;
                case 2:
                    localStorage.setItem("lis241hasMerge", this.hasMerge);
                    break;
                case 3:
                    localStorage.setItem("lis241onlyrptunit", this.onlyrptunit);
                    break;
                case 4:
                    localStorage.setItem("lis241isemer", this.isemer);
                    break;
                default:
                    break;
            }
        },
        showhelp(t){
            this.$pub.showhelp(this, t);
        },
    },
};
</script>

<style scoped>
/deep/.el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
/deep/.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
.pagetop {
    left: 0;
    right: 0;
    height: 215px;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
    overflow-x: auto;
    white-space: nowrap;
}
.pagebottom {
    position: absolute;
    width: 100%;
    left: 0;
    margin-top: 4px;
    height: 36px;
    bottom: 0px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
}
.middle-right {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: visible;
    width: 100%;
    right: 0px;
}

table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
/* table tr td:nth-child(1) {
    width: 80px;
} */
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
.avatar {
    width: 178px;
    height: 178px;
    display: block;
}

.avatar-uploader-icon1 {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 50px;
    line-height: 50px;
    text-align: center;
}
.avatar1 {
    width: 178px;
    height: 50px;
    display: block;
}
.middle-tab-top {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 200px;
}
.middle-bottom {
    position: absolute;
    top: 37px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.middle-tab-bottom {
    position: absolute;
    top: 203px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
/deep/.colred {
    background-color: red !important;
}
/deep/.colgreen {
    background-color: #00ff00 !important;
}
/deep/.colrow {
    background-color: #c0ffc0;
}
</style>
